<template>
  <div class="modify_container">
    <div class="modify_box">

      <el-form
        ref="modifyFormRef"
        :model="modifyForm"
        label-width="0px"
        class="modify_form"
        :rules="modifyFormRules"
      >
      <div class="modify_header">
        <h1>修改密码</h1>
      </div>
        <!-- 新密码 -->
        <el-form-item prop="new">
          <span>新密码</span>
          <el-input
            v-model="modifyForm.new"
            type="password"
          ></el-input>
        </el-form-item>
        <!-- 确认密码 -->
        <el-form-item prop="confirm">
          <span>确认密码</span>
          <el-input
            v-model="modifyForm.confirm"
            type="password"
          ></el-input>
        </el-form-item>

        <!-- 按钮区域 -->
        <el-form-item class="btn">
          <el-button type="primary"  @click="sureChange">确认修改</el-button>
        </el-form-item>
        <!-- 弹出框 -->
        <el-dialog
         title="确认修改"
         :visible.sync="addDialogVisible"
         width="45%"
         @close="addDialogClosed">
         <!-- 内容区域 -->
        <h2>密码修改成功</h2>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="login">返 回 登 录</el-button>
  </span>
</el-dialog>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      modifyForm: {
        new: "",
        confirm: "",
      },
       addDialogVisible: false,
       modifyFormRules: {
        new: [
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        confirm: [
          { required: true, message: '请确认新密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    };
  },

  methods: {
    async sureChange() {
     console.log(this.modifyForm.new);
     console.log(this.modifyForm.confirm);
      if(this.modifyForm.new == this.modifyForm.confirm){
      const {data: res} = await this.$http.post('/api/user/change2',{password:this.modifyForm.new,account:sessionStorage.getItem('account')})
        console.log(res);
        this.addDialogVisible= true
      }else{
        console.log(456);
      }
      // this.$http.post('/api/user/change3',this.)
    },
     login() {
      this.$router.push("/login");
    },
        // 监听添加用户对话框的关闭事件
    addDialogClosed() {
      this.$refs.addFormRef.resetFields()
    },
  },
};
</script>

<style>
.modify_container {
  background: url("https://gitee.com/zj095/cloudimg/raw/master/202110141056833.png");
  height: 100%;
}

.modify_box {
  width: 450px;
  height: 350px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.modify_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 40px;
  box-sizing: border-box;
}

.btn {
  display: flex;
  justify-content: center;
}
.modify_header {
  text-align: center;
}
.el-dialog__body {
    padding: 18px 34px !important;
    color: #606266;
    font-size: 14px;
    word-break: break-all;
}
.el-dialog__footer {
    padding: 9px 44px 20px !important;
    text-align: right;
    box-sizing: border-box;
}
</style>